package a10_动态规划;

import java.util.Scanner;

/**
 * <p>
 * a11_01背包理论基础复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/3/11
 */
public class a11_背包理论基础1复习3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int num = scanner.nextInt();
        int maxWeight = scanner.nextInt();

        int[] weight = new int[num];
        int[] value = new int[num];

        for (int i = 0; i < weight.length; i++) {
            weight[i] = scanner.nextInt();
        }

        for (int i = 0; i < value.length; i++) {
            value[i] = scanner.nextInt();
        }

        //dp[i][j]：0~i的物品中，放满容量为j的背包的最大价值为dp[i][j]

        //递推公式：
        //包含i：dp[i-1][j-weight[i]] + value[i]
        //不包含i：dp[i-1][j]

        //初始化：dp[0][j]

        int[][] dp = new int[num][maxWeight+1];
        for (int j = 0; j <= maxWeight; j++) {
            if(weight[0] <= j){
                dp[0][j] = value[0];
            }
        }

        for (int i = 1; i < weight.length; i++) {
            for (int j = 0; j <= maxWeight; j++) {
                if(j >= weight[i]){
                    dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-weight[i]] + value[i]);
                }else {
                    dp[i][j] = dp[i-1][j];
                }

            }
        }

        System.out.println(dp[num-1][maxWeight]);
    }
}
